1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.universAAL.samples.util.mini;
23
24 import org.osgi.framework.BundleActivator;
25 import org.osgi.framework.BundleContext;
26 import org.universAAL.middleware.container.ModuleContext;
27 import org.universAAL.middleware.container.osgi.uAALBundleContainer;
28 import org.universAAL.middleware.context.ContextEvent;
29 import org.universAAL.middleware.context.ContextEventPattern;
30 import org.universAAL.middleware.service.CallStatus;
31 import org.universAAL.middleware.service.ServiceCall;
32 import org.universAAL.middleware.service.ServiceResponse;
33 import org.universAAL.middleware.ui.UIResponse;
34 import org.universAAL.middleware.util.Constants;
35 import org.universAAL.ontology.location.Location;
36 import org.universAAL.ontology.profile.User;
37 import org.universAAL.ontology.profile.service.ProfilingService;
38 import org.universAAL.support.utils.ICListener;
39 import org.universAAL.support.utils.ISListener;
40 import org.universAAL.support.utils.IUIListener;
41 import org.universAAL.support.utils.UAAL;
42 import org.universAAL.support.utils.context.Pattern;
43 import org.universAAL.support.utils.service.Path;
44 import org.universAAL.support.utils.service.mid.UtilEditor;
45 import org.universAAL.support.utils.ui.Forms;
46 import org.universAAL.support.utils.ui.low.Dialog;
47
48 public class Activator implements BundleActivator {
49
50 public static BundleContext osgiContext = null;
51 public static ModuleContext context = null;
52
53 private static String NAMESPACE = "http://ontology.itaca.upv.es/Test.owl#";
54
55 private UAAL u;
56
57 public void start(BundleContext bcontext) throws Exception {
58
59 Activator.osgiContext = bcontext;
60 Activator.context = uAALBundleContainer.THE_CONTAINER
61 .registerModule(new Object[] { bcontext });
62
63
64 u = new UAAL(context);
65
66
67 Pattern cep = new Pattern(User.MY_URI, User.PROP_PHYSICAL_LOCATION, null);
68 u.subscribeC(new ContextEventPattern[] { cep }, new ICListener() {
69 public void handleContextEvent(ContextEvent event) {
70 System.out.println(">>> Received Event: " + event.toString());
71 }
72 });
73
74
75 User user1 = new User(Constants.uAAL_MIDDLEWARE_LOCAL_ID_PREFIX + "saied");
76 user1.setLocation(new Location(NAMESPACE + "loc1"));
77 ContextEvent e = new ContextEvent(user1, User.PROP_PHYSICAL_LOCATION);
78 u.sendC(e);
79
80
81 u.provideS(UtilEditor.getServiceProfiles(NAMESPACE,
82 ProfilingService.MY_URI,
83 Path.at(ProfilingService.PROP_CONTROLS).path, User.MY_URI),
84 new ISListener() {
85 public ServiceResponse handleCall(ServiceCall s) {
86 System.out.println(">>> Received Service Call: " + s.toString());
87 return new ServiceResponse(CallStatus.succeeded);
88 }
89 });
90
91
92 ServiceResponse r = u.callS(UtilEditor.requestRemove(
93 ProfilingService.MY_URI,
94 Path.at(ProfilingService.PROP_CONTROLS).path, user1));
95 System.out.println(">>> Received Service Response: "+ r.getCallStatus());
96
97
98 Dialog d = new Dialog(user1,"UI example");
99 d.add(Forms.out("Result:", "Successfully reached UI test"));
100 d.addSubmit(Forms.submit(NAMESPACE + "button1", "OK"));
101 u.requestUI(d, new IUIListener() {
102 public void handleUIResponse(UIResponse r) {
103 System.out.println(">>> Received UI Response: " + r.getSubmissionID());
104 }
105 });
106
107 }
108
109 public void stop(BundleContext arg0) throws Exception {
110
111 u.terminate();
112 }
113
114 }